﻿Imports BUS

Public Class frmDiaPhuong

    Private Function TrapKey(ByVal KCode As String) As Boolean
        If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
            TrapKey = False
        Else
            TrapKey = True
        End If
    End Function

    Private Sub txtSoGioNang_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoGioNang.KeyPress
        e.Handled = TrapKey(Asc(e.KeyChar))
    End Sub

    Private Sub btnThemMoi_Click(sender As System.Object, e As System.EventArgs) Handles btnThemMoi.Click
        If txtTenDiaPhuong.Text = "" Or txtSoGioNang.Text = "" Then
            MessageBox.Show("Chưa nhập đủ dữ liệu cần thiết.", "Lổi", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            Dim result = DiaPhuongBUS.ThemDiaPhuong(txtTenDiaPhuong.Text, Integer.Parse(txtSoGioNang.Text))
            If result = True Then
                MessageBox.Show("Thêm thành công !!!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.Close()
            Else
                MessageBox.Show("Thêm thất bại !!!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End If
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class